package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

public class TextReader extends AppCompatActivity {

    FrameLayout frameLayout;
    Drawable background;
    TextView tv;
    float ini_text_size,changed_text_size;
    int text_color;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_reader);

        frameLayout = findViewById(R.id.bg);
        tv = findViewById(R.id.tv_content);
        ini_text_size = tv.getTextSize();
        text_color = Color.BLACK;
        this.registerForContextMenu(tv);
    }
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        getMenuInflater().inflate(R.menu.context_menu,menu);
        super.onCreateContextMenu(menu, v, menuInfo);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_menu,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {

        switch (item.getItemId())
        {
            case R.id.text_color_black:
                text_color = Color.BLACK;
                break;
            case R.id.text_color_yellow:
                text_color = Color.YELLOW;
                break;
            case R.id.text_color_green:
                text_color = Color.GREEN;
                break;
            case R.id.text_color_red:
                text_color = Color.RED;
                break;
            case R.id.text_color_blue:
                text_color = Color.BLUE;
                break;
        }
        tv.setTextColor(text_color);
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onContextItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId())
        {
            case R.id.size_big:
                changed_text_size = ini_text_size +5;
                break;
            case R.id.size_mid:
                changed_text_size = ini_text_size;
                break;
            case R.id.size_small:
                changed_text_size = ini_text_size -5;
                break;

        }
        tv.setTextSize(changed_text_size);
        return super.onOptionsItemSelected(item);

    }
}
